﻿using System.Collections.Generic;
using System.Linq;
using Soundteller.AudioVisual.Model;
using Soundteller.AudioVisual.Model.Interfaces;
using Soundteller.AudioVisual.Repositories.Interfaces;
using System;

namespace Soundteller.AudioVisual.Repositories
{
    public class PadRepository : MemoryRepositoryBase, IPadRepository
    {
        public PadRepository(IMemoryContext context)
            : base(context)
        {
        }

        public IEnumerable<Pad> GetByGraphicCategory(string category)
        {
            return (from pad in Context.Pads
                    where pad.Graphic.Categories.Contains(category)
                    select pad).ToList();
        }

        public void Add(Pad pad)
        {
            if (pad == null) throw new ArgumentNullException("pad");

            Context.Pads.Add(pad);
        }

        public Pad GetBySoundName(string name)
        {
            if (name == null) throw new ArgumentNullException("name");

            return Context.Pads.SingleOrDefault(p => p.Sound.Name == name);
        }
    }
}
